package com.st.rzs.util;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

/**
 * 
 * 消息返回实体二
 * </p>
 * 
 */
public class ResponseModel implements Serializable {

	private static final long serialVersionUID = 1L;

	public String code;
	public String message;
	public Object data;

	public ResponseModel(String code, String message, Object data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public ResponseModel(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public ResponseModel() {
		this.code = "1";
	}

	public ResponseModel(String code) {
		this.code = code;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	/**
	 * 生成请求成功信息，返回data
	 * 
	 * @param data
	 * @return
	 */
	public static final ResponseModel createOkResponse(Object data) {
		return new ResponseModel(ResponseEnum.OK.getCode(), ResponseEnum.OK.getDescription(), data);
	}

	/**
	 * 生成请求成功信息，无返回data
	 * 
	 * @param data
	 * @return
	 */
	public static final ResponseModel createOkResponse() {
		return new ResponseModel(ResponseEnum.OK.getCode(), ResponseEnum.OK.getDescription());
	}

	/**
	 * 生成返回结果为空
	 * 
	 * @param data
	 * @return
	 */
	public static final ResponseModel createNullResponse() {
		return new ResponseModel(ResponseEnum.NOT_FOUND.getCode(), ResponseEnum.NOT_FOUND.getDescription());
	}

	/**
	 * 生成业务请求业务验证失败等信息，输入提示信息
	 * 
	 * @param message
	 *            业务失败提示信息
	 * @return
	 */
	public static final ResponseModel createBussFailedResponse(String message) {

		if (StringUtils.isNotBlank(message)) {
			return new ResponseModel(ResponseEnum.FAILED.getCode(), message);
		} else {
			return new ResponseModel(ResponseEnum.FAILED.getCode(), ResponseEnum.FAILED.getDescription());
		}

	}

	/**
	 * 生成请求异常信息，
	 * 
	 * @return
	 */
	public static final ResponseModel createExpeFailedResponse() {
		return new ResponseModel(ResponseEnum.EXPECTATION_FAILED.getCode(),
				ResponseEnum.EXPECTATION_FAILED.getDescription());
	}

}
